﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

namespace Web_HengliSeed.Sys_Manage
{
    public partial class M_EditNewsInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ClassFile.Function.CheckState();
            if (!IsPostBack)
            {
                LoadData();
                BindDDL();
            }
        }

        private void BindDDL()
        {
            string lan = "cn";
            if (!String.IsNullOrEmpty(Request["lan"]))
                lan = Request["lan"];
            DDLProClass.DataSource = BLL.NewsInfo.GetClassMesAll(lan);
            DDLProClass.DataTextField = "T_NewsClassName";
            DDLProClass.DataValueField = "T_NewsClassID";
            DDLProClass.DataBind();
        }
        private void LoadData()
        {
            string strPID = Common.GetMes.GetRequestQuery(Request, "PID");
            if (!string.IsNullOrEmpty(strPID))
            {
                OleDbDataReader DataRead = BLL.NewsInfo.GetNewsInfo(strPID);
                if (DataRead.HasRows)
                {
                    DataRead.Read();
                    txtProName.Value = Server.HtmlDecode(DataRead["T_NewsTitle"].ToString());
                    txtContent.Value = Server.HtmlDecode(DataRead["T_NewsNote"].ToString());
                    DDLProClass.SelectedValue = DataRead["T_NewsClassID"].ToString();
                }
                DataRead.Close();
                DataRead.Dispose();
            }
        }

        protected void BtnSave_Click(object sender, EventArgs e)
        {
            string strPID = Common.GetMes.GetRequestQuery(Request, "PID");
            string strProName = Server.HtmlEncode(txtProName.Value.Trim());
            string lan = "cn";
            if (!String.IsNullOrEmpty(Request["lan"]))
                lan = Request["lan"];
            if (BLL.NewsInfo.EditNewsMes(strPID, strProName, DDLProClass.SelectedValue, Server.HtmlEncode(txtContent.Value.Trim()), lan))
            {
                
                if (!string.IsNullOrEmpty(strPID))
                {
                    Common.ShowMessage.Show(Page, "error", "信息保存成功...", "M_NewsList.aspx");
                }
                else
                {
                    Common.ShowMessage.myScriptMes(Page, "Suess", "if(confirm(\"信息保存成功，是否继续添加？否则返回信息列表。\")) {location.href=\"M_EditNewsInfo.aspx?lan=" + lan + "\"} else  {location.href=\"M_NewsList.aspx?lan=" + lan + "\"} ");
                }
            }
            else
            {
                Common.ShowMessage.Show(Page, "error", "信息保存失败， 请重试或联系管理人员...");
            }
        }
    }
}
